package com.edu.gdkm.servlet.film;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.edu.gdkm.dao.dypDao;
import com.edu.gdkm.db.table.filmList;

@WebServlet("/filmListServlet")
public class filmListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 电影列表
        List<filmList> filmLists;

        try {
            // 数据库操作类
            dypDao dao = new dypDao();
            // 查询
            filmLists = dao.getFilmLists(dao.select("*", "film"));
            // 关闭
            dao.close();
        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        // 会话域
        HttpSession session = req.getSession();
        session.setAttribute("filmList", filmLists);
        // 转发 => 电影列表详情页面
        req.getRequestDispatcher("filmList.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
